//Declares the class to support Rest communication.
@RestController
//Rest methods shall be addressable under the subdomina "/customers"
@RequestMapping("/customers")
public class CustomersAsJSON {

	//Use previous described class CustomerDomain class automatically
	//Let the Spring framework wire the given variable with a living 
	//repository instance in the background at start up again
    @Autowired
    CustomerDomain customerDomain;

    //Further specific Java Annotations supported by the Spring framework
    //for processing Rest requests
    @RequestMapping(value = "getall", method = RequestMethod.GET)
    @ResponseBody
    ResponseEntity<String> getAll() {

        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/rest; charset=utf-8");
        List<Customer> result = customerDomain.findAllCustomers();

        return new ResponseEntity<String>(CustomerToJsonConverter.toJsonArray(result), headers, HttpStatus.OK);

    }

    @RequestMapping(value = "/create", method = RequestMethod.POST, headers = "Accept=application/rest")
    public ResponseEntity<String> createFromJsonArray(@RequestBody String json) {

        for (Customer customer: CustomerToJsonConverter.fromJsonArrayToCustomers(json)) {
            customerDomain.saveCustomer(customer);
        }
        //Further logic here ...
    }
    //Further methods supporting Rest here ...
}